package com.ruoyi.web.controller.campus;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.campus.domain.MyPriceList;
import com.ruoyi.campus.service.IMyPriceListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 悬赏榜Controller
 *
 * @author zht
 * @date 2021-10-24
 */
@RestController
@RequestMapping("/campus/priceList")
public class MyPriceListController extends BaseController
{
    @Autowired
    private IMyPriceListService myPriceListService;

    /**
     * 查询悬赏榜列表(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping("/getPriceList")
    public TableDataInfo getPriceList(MyPriceList myPriceList){
        startPage();
        List<MyPriceList> list = myPriceListService.getPriceList(myPriceList);
        return getDataTable(list);
    }

    /**
     * 查询悬赏榜列表
     */
    @PreAuthorize("@ss.hasPermi('campus:priceList:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyPriceList myPriceList)
    {
        startPage();
        List<MyPriceList> list = myPriceListService.selectMyPriceListList(myPriceList);
        return getDataTable(list);
    }

    /**
     * 导出悬赏榜列表
     */
    @PreAuthorize("@ss.hasPermi('campus:priceList:export')")
    @Log(title = "悬赏榜", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyPriceList myPriceList)
    {
        List<MyPriceList> list = myPriceListService.selectMyPriceListList(myPriceList);
        ExcelUtil<MyPriceList> util = new ExcelUtil<MyPriceList>(MyPriceList.class);
        return util.exportExcel(list, "悬赏榜数据");
    }

    /**
     * 获取悬赏榜详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:priceList:query')")
    @GetMapping(value = "/{offerId}")
    public AjaxResult getInfo(@PathVariable("offerId") String offerId)
    {
        return AjaxResult.success(myPriceListService.selectMyPriceListByOfferId(offerId));
    }

    /**
     * 新增悬赏榜
     */
    @PreAuthorize("@ss.hasPermi('campus:priceList:add')")
    @Log(title = "悬赏榜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyPriceList myPriceList)
    {
        myPriceList.setOfferId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myPriceListService.insertMyPriceList(myPriceList));
    }

    /**
     * 新增悬赏榜(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @Log(title = "悬赏榜", businessType = BusinessType.INSERT)
    @PostMapping("/addForWx")
    public AjaxResult addForWx(@RequestBody MyPriceList myPriceList)
    {
        myPriceList.setOfferStatus("3");
        myPriceList.setOfferId(UUID.randomUUID().toString().replace("-",""));
        return toAjax(myPriceListService.insertMyPriceList(myPriceList));
    }

    /**
     * 获取我发布的悬赏榜信息(小程序端接口)
     */
    @PreAuthorize("@ss.hasAnyRoles('Administrator,member')")
    @GetMapping("/getMyPriceList")
    public TableDataInfo getMyPriceList(@RequestParam("iuserId") String iuserId){
        startPage();
        List<Map<String,Object>> list = myPriceListService.getMyPriceList(iuserId);
        return getDataTable(list);
    }


    /**
     * 修改悬赏榜
     */
    @PreAuthorize("@ss.hasPermi('campus:priceList:edit')")
    @Log(title = "悬赏榜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyPriceList myPriceList)
    {
        return toAjax(myPriceListService.updateMyPriceList(myPriceList));
    }

    /**
     * 删除悬赏榜
     */
    @PreAuthorize("@ss.hasPermi('campus:priceList:remove')")
    @Log(title = "悬赏榜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{offerIds}")
    public AjaxResult remove(@PathVariable String[] offerIds)
    {
        return toAjax(myPriceListService.deleteMyPriceListByOfferIds(offerIds));
    }
}
